#define  _CRT_SECURE_NO_WARNINGS


#include<stdio.h>
#include<string.h>


int main()
{
    char arr[301] = { 0 };
    char* str[100] = { 0 };
    scanf("%s", arr);
    int len = 0, i = 0, x = 0, y = 0, j = 0, temp = 0, k = 0, flag = 0;
    str[0] = strtok(arr, ",");
    while (str[i] != NULL)
    {
        str[++i] = strtok(NULL, ",");
    }
    if (strstr(str[0], str[1]) != NULL && strstr(str[0], str[1]) != NULL)
    {
        len = strlen(str[0]);
        for (i = 0; i < len; i++)
        {
            if (str[0][i] == str[1][0])
            {
                temp = strlen(str[1]);
                flag = 1;
                for (j = 0, k = i; temp; j++, k++)
                {
                    if (str[0][k] != str[1][j])
                    {
                        flag = 0;
                        break;
                    }
                    temp--;
                }
                if (flag == 1)
                {
                    x = k - 1;
                    break;
                }
            }
        }
        for (i = 0; i < len; i++)
        {
            if (str[0][i] == str[2][0])
            {
                temp = strlen(str[2]);
                flag = 1;
                for (j = i, k = 0; temp; j++, k++)
                {
                    if (str[0][j] != str[2][k])
                    {
                        flag = 0;
                        break;
                    }
                    temp--;
                }
                if (flag == 1)
                {
                    y = i;
                }
            }
        }
        printf("%d\n", y - x - 1);
    }
    else
        printf("-1\n");
    return 0;
}